package com.study.concurrent.A_ThreadManagement.i_UseThreadLocalVariable;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Created by 赵超 on 2017/3/19.
 */
public class UnsafeTask implements Runnable {
    private Date startDate;
    @Override
    public void run() {
        startDate = new Date();
        System.out.printf("线程 %s 开始 : %s\n", Thread.currentThread().getId(), startDate);
        try {
            TimeUnit.SECONDS.sleep((long) Math.rint(Math.random() * 10));//Math.rint()方法返回与传入数字最为接近的数字，如果存在两个数字同样接近，则返回偶数的那个
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.printf("线程 %s 结束 : %s\n", Thread.currentThread().getId(), startDate);
    }
}
